#!/bin/bash

case $1 in
    help)
        echo "帮助:"
        echo "vol  ---> 查看当前音量"
        echo "vol+ ---> 增大音量 [+2%]"
        echo "vol+ ---> 减小音量 [-2%]"
        echo "vols ---> 设置音量 [eg: wmcommand vols 25]"
        echo "vol0 ---> 扬声器 静音"
        echo "vol1 ---> 麦克风 静音"
        echo ""
        echo "li   ---> 查看屏幕亮度"
        echo "li+  ---> 增加亮度 [+2%]"
        echo "li-  ---> 降低亮度 [-2%]"
        echo "lis  ---> 设置亮度 [eg: wmcommand lis 90]"
        echo ""
        echo "clon  --->  开启 clash-main [docker] + 开启代理 [系统代理 git代理]"
        echo "clof  --->  关闭 clash-main [docker] + 关闭代理 [系统代理 git代理]"
        echo "clona --->  开启 clash-main clash-web [docker] + 开启代理 [系统代理 git代理]"
        echo "clofa --->  关闭 clash-main clash-web [docker] + 关闭代理 [系统代理 git代理]"
        echo ""
        echo "rest  ---> 休眠"
        echo ""
        echo "bcon  ---> 连接蓝牙耳机 [xiaomi]"
        echo "bdis  ---> 断开蓝牙耳机 [xiaomi]"
        echo ""
        echo "wallc ---> 更换壁纸"
        echo ""
        echo "cpu0  ---> performance 最大频率"
        echo "cpu1  ---> powersave   最小频率"
        echo "cpu2  ---> ondemand    按需快速动态调整CPU频率"
        echo "cpu3  ---> schedutil   基于调度程序调整 CPU 频率 (默认)"
        echo "cpus  ---> 查看当前cpu模式"
        echo ""
        echo "skey  ---> 开启或关闭 按键显示"
        ;;
    vol)
        printf "当前音量为: "
        pactl list sinks | grep front | tail -1 | awk '{print $4}' | cut -d'%' -f1
        ;;
    vol+)
        volNum=`pactl list sinks | grep 信宿 | wc -l`
        volUse=`pactl list sinks | grep 信宿 | tail -1 | cut -d'#' -f2`
    	pactl set-sink-volume $volUse +2%
        #if [[ $volNum -gt 1  ]]; then
    	#    pactl set-sink-volume $volUse +2%
    	#else
    	#    pactl set-sink-volume $volUse +2%
    	#fi
	;;
    vol-)
    	volNum=`pactl list sinks | grep 信宿 | wc -l`
    	volUse=`pactl list sinks | grep 信宿 | tail -1 | cut -d'#' -f2`
    	pactl set-sink-volume $volUse -2%
    	#if [[ $volNum -gt 1  ]]; then
    	#    pactl set-sink-volume $volUse -2%
    	#else
    	#    pactl set-sink-volume $volUse -2%
    	#fi
	;;
    vols)
    	volUse=`pactl list sinks | grep 信宿 | tail -1 | cut -d'#' -f2`
    	pactl set-sink-volume $volUse $2%
        printf "当前音量为: "
        pactl list sinks | grep front | tail -1 | awk '{print $4}' | cut -d'%' -f1
        ;;
    vol0)
        pactl set-sink-mute 0 toggle ;;
    vol1)
        pactl set-source-mute 1 toggle ;;
    li)
        printf "当前屏幕亮度为: "
        xbacklight -get ;;
    li+)
        xbacklight -inc 2 ;;
    li-)
        xbacklight -dec 2 ;;
    lis)
        xbacklight -set $2
        printf "当前屏幕亮度为: "
        xbacklight -get ;;
    clon)
        docker restart clash-main
        proxysh on ;;
    clof)
        docker stop clash-main
        proxysh off ;;
    clona)
        docker restart clash-main clash-web
        proxysh on ;;
    clofa)
        docker stop clash-main clash-web
        proxysh off ;;
    rest)
        sudo sh -c "echo mem > /sys/power/state" ;;
    bcon)
        bluetoothMAC='14:0A:29:00:76:14'
        wait='5'
        bluetoothctl power on
        timeout $wait bluetoothctl scan on > /tmp/bluetooth.log && bluetoothctl scan off
        status=`grep $bluetoothMAC /tmp/bluetooth.log | wc -l`
        if [[ $status -ge 1   ]]; then
    	    bluetoothctl connect $bluetoothMAC
    	    printf "\nbluetooth connect ing...\n"
    	else
    	    printf "\nbluetooth no find!\n"
    	fi ;;
    bdis)
        bluetoothMAC='14:0A:29:00:76:14'
        bluetoothctl disconnect $bluetoothMAC ;;
    wallc)
        /bin/bash /opt/software/scripts/wallpaper-change.sh ;;
    cpu0)
        echo "performance 最大频率"
        sudo cpupower frequency-set -g performance ;;
    cpu1)
        echo "powersave 最小频率"
	sudo cpupower frequency-set -g powersave ;;
    cpu2)
        echo "ondemand 按需快速动态调整CPU频率"
	sudo cpupower frequency-set -g ondemand ;;
    cpu3)
        echo "schedutil 基于调度程序调整 CPU 频率 (默认)"
        sudo cpupower frequency-set -g schedutil ;;
    cpus)
        echo "查看当前cpu模式:"
        sudo cat /sys/devices/system/cpu/cpu[0-15]*/cpufreq/scaling_governor ;;
    skey)
        CONNECTED_MONITORS=$(xrandr --listmonitors | sed 1d | awk '{print $4}' | wc -l)
        case $CONNECTED_MONITORS in
            1) killall screenkey || screenkey -p fixed -g 66%x8%+17%-5% & ;;
            2) killall screenkey || screenkey -p fixed -g 50%x8%+25%-11% & ;;
        esac
    ;;
    *) echo -e "input error!\n可以在第一个参数位置输入 help, 查看帮助" ;;
esac
